<template>
  <div class="comment-info" v-if="isShowComp">
    <!-- 评论头 -->
    <div class="info-header">
      <div class="header-title">用户评价</div>
      <div class="header-more">
        更多
        <i class="arrow-right"></i>
      </div>
    </div>

    <!-- 用户信息 -->
    <div class="info-user">
      <img class="user-icon" v-lazy="commentInfo.user.avatar" alt />
      <span class="user-text">{{ commentInfo.user.uname }}</span>
    </div>

    <!-- 评论详情信息 -->
    <div class="info-detail">
      <p class="detail-text">{{ commentInfo.content }}</p>
      <div class="info-other">
        <span class="date">{{ commentInfo.created | showDate }}</span>
        <span>{{ commentInfo.style }}</span>
      </div>
    </div>

    <!-- 评论图片 -->
    <div class="info-imgs">
      <img v-lazy="item" v-for="item in commentInfo.images" :key="item" alt />
    </div>
  </div>
</template>

<script>
import { formatDate } from "utils/utils";

export default {
  name: "DetailCommentInfo",

  // 父组件数据
  props: {
    commentInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },

  // 过滤器
  filters: {
    showDate(value) {
      let date = new Date(value * 1000);
      return formatDate(date, "yyyy-MM-dd");
    },
  },

  // 计算属性
  computed: {
    isShowComp() {
      return Object.keys(this.commentInfo).length != 0;
    },
  },
};
</script>

<style lang="less" scoped>
.comment-info {
  padding: 5px 12px 10px;
  color: #333333;
  border-bottom: 5px solid #f2f5f8;
  .info-header {
    display: flex;
    height: 50px;
    // flex垂直居中
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);

    .header-more {
      font-size: 13px;
    }
  }
  .info-user {
    padding: 10px 0 5px;
    .user-icon {
      margin-right: 10px;
      width: 42px;
      height: 42px;
      border-radius: 50%;
      vertical-align: middle;
    }
    .user-text {
      font-size: 15px;
    }
  }
  .info-detail {
    padding: 0 5px 15px;
    .detail-text {
      font-size: 14px;
      color: #777777;
      line-height: 1.5;
    }
    .info-other {
      margin-top: 10px;
      font-size: 12px;
      color: #999999;
      .date {
        margin-right: 8px;
      }
    }
  }
  .info-imgs {
    margin-top: 10px;
    img {
      width: 70px;
      height: 70px;
      margin-right: 5px;
    }
  }
}
</style>